﻿/*
 * @Author: zhoujinlong 765637726@qq.com
 * @Date: 2024-05-14 16:15:49
 * @LastEditors: zhoujinlong 765637726@qq.com
 * @LastEditTime: 2024-05-29 09:16:39
 * @FilePath: \若依-back\public\static\js\config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 *配置文件
 */

/*==========================配置部分==可修改参数部分============================================*/
var roomConfig = {
	background: "url('../img/bg2.jpg')",
	cameraPostion: {
		x: -5302,
		y: 4288,
		z: 5047
	},
	cameraTarget: { //初始摄像机焦点
		x: -1028,
		y: 698,
		z: 338
	}
}



//双击机柜 进入单机柜页面时显示在左侧的内容
//可以自定义
function showCabnetCustomDetail(dataid, modelname, closeFunc) {
	console.log('ms', dataid, modelname)
	layer.closeAll();
	// `http://10.66.164.6/api/business/cmdb/roomorrack/getByIdAlone/${dataid}`
	// httpGetSyn( webapi.serverHead + `/business/cmdb/roomorrack/getByIdAlone/${dataid}`, function (
	httpGetSyn( '../dataDemo/buildData.json', function (
		response) {
		console.log(response)
		if (response && response.data) {
			let data = response.data
			//显示机柜详情
			var contentHtml = "<div id='canNetDetail' style='position: absolute;top: 100px;left: 80px;    background: rgba(23,57 ,92,0.45);padding: 20px;'>\
				            <table class='cabDetail'>\
				            <tr><td colspan=2 style='text-align:left;font-size: 20px;'><font onclick='modelBussiness.backBtn();' style='cursor:pointer;color:#50ff02;' >《《《&nbsp;&nbsp;返回</a></td></tr>\
				            <tr><td colspan=2 style='text-align:left;font-size: 20px;'>&nbsp;</td></tr>\
				            <tr><td colspan=2 style='text-align:left;font-size: 20px;'>机柜信息</td></tr>\
				            <tr><td colspan=2 class='tdTitile'>&nbsp;</td></tr>\
							<tr><td colspan=2 class='tdTitile'>key</td></tr>\
							<tr><td colspan=2 class='tdContent'>" + data.cr_key + "</td></tr>\
				            <tr><td colspan=2 class='tdTitile'>名称</td></tr>\
				            <tr><td colspan=2 class='tdContent'>" + data.roomorrack_name + "</td></tr>\
							<tr><td colspan=2 class='tdTitile'>运营状态</td></tr>\
							<tr><td colspan=2 class='tdContent'>" + (data.roomorrack_status == '1' ? '待运营' : (data.roomorrack_status ==
					'2' ? '运营中' : '已下架')) + "</td></tr>\
				            <tr><td colspan=2 class='tdTitile'>品牌</td></tr>\
				            <tr><td colspan=2  class='tdContent'>" + (data.roomorrack_brand || '无') + "</td></tr>\
				            <tr ><td colspan=2 class='tdTitile'>型号</td></tr>\
				            <tr><td colspan=2  class='tdContent'>" + (data.roomorrack_model  || '无')+ "</td></tr>\
				            <tr style='display:none;'><td colspan=2 class='tdTitile'>物理位置</td></tr>\
				            <tr style='display:none;'><td colspan=2  class='tdContent'>" + (data.roomorrack_location || '无') + "</td></tr>\
				            <tr><td colspan=2 class='tdTitile'>最大U位</td></tr>\
				            <tr><td colspan=2  class='tdContent'>" + data.roomorrack_U + 'U' + "</td></tr>\
				            <tr><td colspan=2 class='tdTitile'>空间利用率</td></tr>\
				            <tr><td colspan=2  class='tdContent'>" + (data.roomorrack_rate * 100).toFixed(0) + '%' + "</td></tr>\
				            <tr style='display:none;'><td colspan=2 class='tdTitile'>温度值</td></tr>\
				            <tr style='display:none;'><td colspan=2  class='tdContent'>" + data.roomorrack_tempturevalue + '℃' + "</td></tr>\
							<tr style='display:none;'><td colspan=2 class='tdTitile'>总承重</td></tr>\
							<tr style='display:none;'><td colspan=2  class='tdContent'>" + data.roomorrack_allbearing + 'kg' + "</td></tr>\
							<tr style='display:none;'><td colspan=2 class='tdTitile'>当前承重</td></tr>\
							<tr style='display:none;'><td colspan=2  class='tdContent'>" + data.roomorrack_bearing + 'kg' + "</td></tr>\
							<tr style='display:none;'><td colspan=2 class='tdTitile'>总功耗</td></tr>\
							<tr style='display:none;'><td colspan=2  class='tdContent'>" + data.roomorrack_alleu + 'kw' + "</td></tr>\
							<tr style='display:none;'><td colspan=2 class='tdTitile'>当前功耗</td></tr>\
							<tr style='display:none;'><td colspan=2  class='tdContent'> " + data.roomorrack_eu + 'kw' + "</td></tr>\
				            <table>\
				            </div>";
			$("#mainBody").append(contentHtml);

			console.log('$("#mainBody")',$("#mainBody"));

		}
	}, function (err) {
		console.log(err);
	});



}
//鼠标滑入机柜时显示机柜的简讯  
//可以自定义
function showCabnetCustomEasyDetail(dataid, modelname, closeFunc) {
	var alarms = modelBussiness.getAlarmsByModelID(modelname);
	console.log(alarms);
	console.log(modelname, dataid)
	var info = webapi.CabInfosCache.Modelobjs["m_" + modelname];
	console.log(webapi.CabInfosCache.Modelobjs)
	console.log('info', info = 1111)
	
	// let data = []
	// httpGetSyn(`http://10.66.164.6/api/business/cmdb/roomorrack/getTemperatures`, function(response) {
	// 	console.log(response)
	// 	if (response && response.data) {
	// 		data = response.data
	// 	}
	// }, function(err) {
	// 	console.log(err);
	// });





	if (info) {

		let data = JSON.parse(sessionStorage.getItem('temperatures')) || []
		let temptureValue = ''
		console.log(data)
		data.forEach(item => {
			console.log(item)
			if (item.id == info.id) {
				temptureValue = item.temptureValue
			}
		})

		var showHtml = "<div><div class='msgtitle'>机柜详细信息</div>\
                            <div class='msgtitle2'>名称：" + info.name + "</div>\
                            <div class='msgtitle2'>告警：</div>\
                            <div class='msgcontent' id='alarmMSg'>" + (alarms ? alarms.length : 0) +
			"</div>\
                            <div class='msgtitle2' style='display:none'>温度：" + temptureValue + '℃' +
			"</div>\
                            <div class='msgcontent' id='temValue'></div>\
                            <div class='msgtitle2'>U位使用率：" + (info.useRate * 100).toFixed(0) +
			"%</div>\
                            <div class='msgcontent'><div style='width:100%;height:20px;border:1px solid grey;background-color:rgba(191, 189, 189, 0.5);'><div style='width:" +
			(info.useRate *
				100) + "%;height:20px;background-color:#27ce27;'></div></div></div>\
                            </div > ";
		layer.tips(showHtml, '#MarkMessageHelper', {
			closeBtn: 1,
			shade: false,
			shadeClose: true,
			area: ["300px", "270px"],
			maxWidth: 1000,
			maxHeight: 350,
			time: 0, //是否定时关闭，0表示不关闭
			cancel: function (index, layero) {
				if (closeFunc) {
					closeFunc();
				}
			},
			success: function () {

			},
			tips: [1, "rgba(0,0,0,0.8)"] //还可配置颜色
		});
	} else {
		layer.tips("该设备未绑定数据", '#MarkMessageHelper', {
			closeBtn: 1,
			shade: false,
			shadeClose: true,
			area: ["200px", "100px"],
			maxWidth: 1000,
			maxHeight: 350,
			time: 0, //是否定时关闭，0表示不关闭
			cancel: function (index, layero) {
				if (closeFunc) {
					closeFunc();
				}
			},
			success: function () { },
			tips: [1, "rgba(0,0,0,0.8)"] //还可配置颜色
		});
	}
}

//鼠标滑入其他设备显示的简讯
//可以自定义
function showDevCustomEasyDetail(dataid, modelname, closeFunc) {
	var alarms = modelBussiness.getAlarmsByModelID(modelname);
	console.log(alarms);
	console.log(webapi); 
	var info = webapi.OtherDevsCache.Modelobjs["m_" + modelname];

	
	console.log('info', info)
	// if (!info || (info.typeName && info.typeName == '空调')) {
	// 	return 
	// }
	if (info && info.typeName && info.typeName == '空调' && info.names) {
		var showHtml = "<div><div class='msgtitle'>设备详细信息</div>\
                            <div class='msgtitle2'>名称：" + info.names + "</div>\
                            <div class='msgtitle2'>型号："+ info.otherParams[0].value + "</div>\
                            <div class='msgtitle2'>PN："+ info.otherParams[1].value + "</div>\
                            <div class='msgtitle2'>序列号："+ info.otherParams[2].value + "</div>\
                            </div > ";
		layer.tips(showHtml, '#MarkMessageHelper', {
			closeBtn: 1,
			shade: false,
			shadeClose: true,
			area: ["300px", "200px"],
			maxWidth: 1000,
			maxHeight: 350,
			time: 0, //是否定时关闭，0表示不关闭
			cancel: function (index, layero) {
				if (closeFunc) {
					closeFunc();
				}
			},
			success: function () {

			},
			tips: [1, "rgba(0,0,0,0.8)"] //还可配置颜色
		});
	} else {
		// layer.tips("该设备未绑定数据", '#MarkMessageHelper', {
		// 	closeBtn: 1,
		// 	shade: false,
		// 	shadeClose: true,
		// 	area: ["200px", "100px"],
		// 	maxWidth: 1000,
		// 	maxHeight: 350,
		// 	time: 0, //是否定时关闭，0表示不关闭
		// 	cancel: function (index, layero) {
		// 		if (closeFunc) {
		// 			closeFunc();
		// 		}
		// 	},
		// 	success: function () { },
		// 	tips: [1, "rgba(0,0,0,0.8)"] //还可配置颜色
		// });
	}
}

function showDevCustomDetail(dataid, modelname, closeFunc) {
	var alarms = modelBussiness.getAlarmsByModelID(modelname);
	console.log(alarms);



	var info = webapi.OtherDevsCache.Modelobjs["m_" + modelname];
	if (info) {
		if (modelname.indexOf("_qiuji_") > 0 || modelname.indexOf("_qiangji_") > 0) {
			//显示详情
			var contentHtml = "<div><video style='width:600px;height:400px;background:black;' src='' /></div>";
			//自定页
			layer.open({
				title: false,
				shade: 0.1,
				area: ['640px', '440px'],
				shadeClose: true, //开启遮罩关闭
				btn: false,
				cancel: function (index, layero) {
					if (closeFunc) {
						closeFunc();
					}
				},
				content: contentHtml
			});
		} else {

			return

			//显示机柜详情
			var contentHtml = "<div>自定义控制按钮等内容</div>";
			//自定页
			layer.open({
				title: false,
				shade: 0.1,
				area: ['340px', '240px'],
				shadeClose: true, //开启遮罩关闭
				btn: false,
				cancel: function (index, layero) {
					if (closeFunc) {
						closeFunc();
					}
				},
				content: contentHtml
			});
		}
	} else {
		// layer.msg("该设备未绑定数据！")
	}
}
//鼠标滑入服务器时显示的信息
//可以自定义
function showServerCustomDetail(modelname, serverid, closeFunc, position) {
	var alarms = modelBussiness.getAlarmsByModelID(modelname);

	const list = webapi.CabInfosCacheAll
	console.log(serverid)
	console.log(list)

	if (serverid && serverid.indexOf('noused') == -1) {
		// `http://10.66.164.6/api/business/cmdb/hostdevice/getByIdAlone/${serverid}
		var showHtml = ""
		var url = 'hostdevice'
		var lname = 'hosts_server'
		list.forEach((item) => {
			console.log(item.id)
			if (item.id == serverid) {
				if (item.img && (item.img != '../img/3dImg/server2.jpg')) {
					url = 'networkdevice'
					if (item.img == '../img/3dImg/fhq.jpg') {
						lname = 'network_firewall'
					} else if (item.img == '../img/3dImg/jhj.jpg') {
						lname = 'network_switch'
					} else if (item.img == '../img/3dImg/lyq.png') {
						lname = 'network_Router'
					} else if (item.img == '../img/3dImg/fzjh.png') {
						lname = 'network_balance'
					}

				}
			}
		})
		// httpGetSyn( webapi.serverHead + `/business/cmdb/${url}/getByIdAlone/${serverid}`, function (response) {
			httpGetSyn( '../dataDemo/buildData.json', function (response) {
			console.log(response)
			if (response && response.data) {
				let data = response.data;
				let iplists = ''
				let ipList = data.ipList || []
				if(ipList.length >0 ){
					ipList.forEach(item => {
						if(item.ipAddress && item.ipAddress.length >0){
							iplists += (JSON.parse(item.ipAddress)[1] + '/')
						}
						
					})
				}
				if(iplists == ''){
					iplists = '无'
				}
				

				if (data.cme_key == 'hosts_server' || data.cme_key == 'network_firewall' || data.cme_key == 'network_switch' || data.cme_key == 'network_balance' || data.cme_key == 'network_Router') { //服务器
					showHtml = "<div><div class='msgtitle2' style='text-align:center;font-weight:800;color:#fff;'>" + (data.cme_key == 'hosts_server' ? '服务器' : (data.cme_key == 'network_firewall' ? '防火墙' : '交换机')) + "</div>\
										<div class='msgtitle2'>资产ID：</div>\
										<div class='msgcontent'>" + data[data.cme_key + '_id'] + "</div>\
										<div class='msgtitle2'>资产名：</div>\
										<div class='msgcontent'>" + data[data.cme_key + '_name'] + "</div>\
										<div class='msgtitle2'>运营状态：</div>\
										<div class='msgcontent'>" + (data[data.cme_key + '_status'] == '1' ? '待运营' : (data[data.cme_key + '_status'] == '2' ?
							'运营中' : '已下架')) + "</div>\
										<div class='msgtitle2'>监控状态：</div>\
										<div class='msgcontent'>" + (data[data.cme_key + '_monitorFor'] == '1' ? '在线' : (data[data.cme_key + '_monitorFor'] ==
							'2' ? '离线' : '未监控')) + "</div>\
										<div class='msgtitle2'>型号：</div>\
										<div class='msgcontent'>" + (data[data.cme_key + '_model'] || '无') + "</div>\
										<div class='msgtitle2'>物理位置：</div>\
										<div class='msgcontent'>" + (data[data.cme_key + '_location'] || '无') + "</div>\
										<div class='msgtitle2'>所属机柜：</div>\
										<div class='msgcontent'>" + data[data.cme_key + '_roomorrack'] + "</div>\
										<div class='msgtitle2'>占用U位：</div>\
										<div class='msgcontent'>" + data[data.cme_key + '_U'] + "</div>\
										<div class='msgtitle2'>是否监控：</div>\
										<div class='msgcontent'>"+ (data[data.cme_key + '_monitors'] == '1' ? '不监控' : '监控') + "</div>\
										<div class='msgtitle2'>IP地址：</div>\
										<div class='msgcontent'>\
										 <span >"+ iplists + " </span>\
										</div>\
										<div class='msgtitle2'>告警：</div>\
										<div class='msgcontent'>" + (alarms ? alarms[0].Alarms[0].alarmDetail : '无') + "</div>\
								    </div > ";

				} else { //存储
					showHtml = "<div><div class='msgtitle2' style='text-align:center;font-weight:800;color:#fff;'>存储</div>\
								<div class='msgtitle2'>资产ID：</div>\
							    <div class='msgcontent'>" + data.hosts_storage_id + "</div>\
							    <div class='msgtitle2'>资产名：</div>\
							    <div class='msgcontent'>" + data.hosts_storage_name + "</div>\
							    <div class='msgtitle2'>运营状态：</div>\
							    <div class='msgcontent'>" + (data.hosts_storage_status == '1' ? '待运营' : (data.hosts_storage_status == '2' ?
							'运营中' : '已下架')) + "</div>\
								<div class='msgtitle2'>品牌：</div>\
								<div class='msgcontent'>"+ data.hosts_storage_brand + "</div>\
							    <div class='msgtitle2'>型号：</div>\
							    <div class='msgcontent'>"+ (data.hosts_storage_model || '无') + "</div>\
								<div class='msgtitle2'>物理位置：</div>\
								<div class='msgcontent'>" + (data.hosts_server_location || '无') + "</div>\
								<div class='msgtitle2'>机房机柜：</div>\
								<div class='msgcontent'>"+ data.hosts_storage_roomorrack + "</div>\
								<div class='msgtitle2'>占用U位：</div>\
								<div class='msgcontent'>"+ data.hosts_storage_U + "</div>\
							   <div class='msgtitle2'>告警：</div>\
							   <div class='msgcontent'>" + (alarms ? alarms[0].Alarms[0].alarmDetail : '无') + "</div>\
							    </div > ";

				}
				console.log(position)

				console.log(window)

				// layer.tips(showHtml, '#MarkMessageHelper', {
				// 	closeBtn: 1,
				// 	shade: false,
				// 	shadeClose: true,
				// 	area: ["300px", "500px"],
				// 	// maxWidth: 1000,
				// 	// maxHeight: 700,
				// 	offset: [position.y + '', position.x + ''],
				// 	time: 0, //是否定时关闭，0表示不关闭
				// 	cancel: function (index, layero) {
				// 		if (closeFunc) {
				// 			closeFunc();
				// 		}
				// 	},
				// 	success: function () {
				// 		// const dom = document.getElementsByClassName('layui-layer-tips')[0];
				// 		// var reg1 = new RegExp("px", "g");
				// 		// var top = dom.style.top.replace(reg1, "");
				// 		// console.log(top)
				// 		// dom.style.display = 'none'
				// 		// if (position.y < 500) {
				// 		// 	if (top < 10) {
				// 		// 		dom.style.top = '10px'
				// 		// 	}
				// 		// 	console.log('yes', dom)
				// 		// } else {

				// 		// 	dom.style.top = (position.y - 437 + 10) + 'px'
				// 		// 		console.log((position.y - 437 + 10))
				// 		// 	console.log('no', dom)
				// 		// }

				// 		// console.log(top)
				// 		// console.log(dom)
				// 		// setTimeout( ()=>{
				// 		// 	dom.style.display = 'block'
				// 		// },100)
				// 	},
				// 	tips: [3, "rgba(0,0,0,0.8)"] //还可配置颜色
				// });
				console.log(position)
				layer.ready(function () {
					// layer.msg('很高兴一开场就见到你');
					layer.tips(showHtml, '#MarkMessageHelper', {
						time: 0, //是否定时关闭，0表示不关闭
						tips: 3,
						area: ["300px", "500px"],
						skin: 'demo-class',
						success: function (layero, index) {
							console.log(layero)
							console.log(layero.offset().top)
							let hv = window.innerHeight - 500;
							let ftop = Math.abs(position.y - hv)
							console.log(window.innerHeight - 500)
							console.log(ftop)
							layero.css("top", Math.abs(layero.offset().top + ftop) );
							// layero.css("top", ftop > 10 ? ftop : 10);
						}

					});
				});



			}
		})


	}






}
//画线
function drawLine(name, path, color) {
	modelBussiness.commonFunc.drawLine(name, path, color);
}
window.parent.drawLine = drawLine;
//移除画线
function removeLine(name) {
	modelBussiness.commonFunc.removeLine(name);
}
window.parent.removeLine = removeLine;

/*==========================通用方法==不可修改部分============================================*/
/*
根据数据id快速寻找设备信息
该方法不用修改
*/
var DevRelationCache = null;

function getRelationInfoByDataId(dataid) {
	if (!DevRelationCache) {
		DevRelationCache = {
			models: {},
			datas: {}
		}
		var devs = getDevsConfig();
		devs = devs.concat(getRacksConfig());
		$.each(devs, function (_index, _obj) {
			_obj.modelId = "";
			if (_obj.type == "rack") {
				_obj.modelId = "rack_" + _obj.id;
				_obj.name = "rack_" + _obj.id;
				DevRelationCache.models["m_rack_" + _obj.id] = _obj;
			} else {
				_obj.modelId = "dev_T_" + _obj.type + "_ID_" + _obj.id;
				DevRelationCache.models["m_dev_T_" + _obj.type + "_ID_" + _obj.id] = _obj;
			}
			DevRelationCache.datas["d_" + _obj.dataId] = _obj;
		});
	}
	return DevRelationCache.datas["d_" + dataid];
}
/*
根据模型id快速寻找设备信息
该方法不用修改
*/
function getRelationInfoByModelId(modelid) {
	getRelationInfoByDataId(0);
	return DevRelationCache.models["m_" + modelid];
}

//配置机柜模型配置信息
function getRacksConfig() { //该方法名固定 在initPage.js modelBusiness.js文件中多次调用
	var racksConfig = [];
	$.each(roomConfig.buildData.racksConfig, function (_index, _obj) {
		if (_obj.children && _obj.children.length > 0) {
			$.each(_obj.children, function (_cindex, _cobj) {
				if (_cobj.type == "rack") {
					racksConfig.push(_cobj);
				}
			})
		} else {
			racksConfig.push(_obj);
		}
	});
	return racksConfig;
}

function getDevsConfig() {
	var devs = roomConfig.buildData.devConfig;
	$.each(roomConfig.buildData.racksConfig, function (_index, _obj) {
		if (_obj.children && _obj.children.length > 0) {
			devs.push(_obj);
			$.each(_obj.children, function (_cindex, _cobj) {
				if (_cobj.type != "rack") {
					devs.push(_cobj);
				}
			})
		}
	});
	return devs;
}